package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.ReturnList;
import com.atguigu.jxc.entity.ReturnListGoods;
import com.atguigu.jxc.service.ReturnListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("returnListGoods")
public class ReturnListGoodsController {

    @Autowired
    private ReturnListGoodsService returnListGoodsService;

    /*
     http://localhost:8080/returnListGoods/save?returnNumber=TH1605768591211（退货单号前端生成）
    请求参数：ReturnList returnList, String returnListGoodsStr
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //退货单保存
    @PostMapping("save")
    public ServiceVO save(ReturnList returnList, String returnListGoodsStr,String returnNumber){
        return returnListGoodsService.save(returnList,returnListGoodsStr,returnNumber);
    }

    /*
   请求URL：http://localhost:8080/returnListGoods/list
   请求参数：String returnNumber,Integer supplierId, Integer state,String sTime,String eTime
   请求方式：POST
   返回值类型：JSON
   返回值：Map<String,Object>
    */
    //退货单列表展示（可条件查询：单据号模糊、供应商、是否付款和日期区间）
    @PostMapping("list")
    public Map<String,Object> list(String returnNumber, Integer supplierId, Integer state, String sTime, String eTime){

        List<ReturnList> list=returnListGoodsService.getList(returnNumber,supplierId,state,sTime,eTime);
        HashMap<String, Object> map = new HashMap<>();
        map.put("rows",list);
        return map;
    }

    /*
    请求URL：http://localhost:8080/returnListGoods/goodsList
    请求参数：Integer returnListId
    请求方式：POST
    返回值类型：JSON
    返回值：Map<String,Object>
     */
    //退货单商品信息
    @PostMapping("goodsList")
    public Map<String,Object> goodsList(Integer returnListId){
        HashMap<String, Object> map = new HashMap<>();
        List<ReturnListGoods> list=returnListGoodsService.goodsList(returnListId);
        map.put("rows",list);
        return map;
    }

    /*
    请求URL：http://localhost:8080/returnListGoods/delete
    请求参数：Integer returnListId
    请求方式：POST
    返回值类型：JSON
    返回值：ServiceVO
     */
    //删除退货单
    @PostMapping("delete")
    public ServiceVO delete(Integer returnListId){
        return returnListGoodsService.deleteByReturnListId(returnListId);
    }

    /*
        请求URL：http://localhost:8080/returnListGoods/updateState
        请求参数：Integer returnListId
        请求方式：POST
        返回值类型：JSON
        返回值：ServiceVO
         */
    @PostMapping("updateState")//从1改为2
    public ServiceVO updateState(Integer returnListId){
        return returnListGoodsService.updateState(returnListId);
    }

    /*
    请求URL：http://localhost:8080/returnListGoods/count
    请求参数：String sTime, String eTime ,Integer goodsTypeId, String codeOrName
    请求方式：POST
    返回值类型：JSON
    返回值：String
     */
    //退货统计（可根据 商品类别、商品编码或名称 条件查询）
    @PostMapping("count")
    public List<Map<String,Object>> count(String sTime, String eTime ,Integer goodsTypeId, String codeOrName){
        return returnListGoodsService.count(sTime,eTime,goodsTypeId,codeOrName);
    }
}
